﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace WorkNodeFramework
{
    internal class WorkNodeUtility
    {
        public static string TrimsPath(string path)
        {
            if (path.EndsWith("/"))
                path = path.Substring(0, path.Length - 1);
            if (!path.StartsWith("/"))
                path = "/" + path;
            return path;
        }

        internal static WorkNodeTypeAttribute GetWorkNodeType<T>()
            where T : WorkNode
        {
            Type type = typeof(T);
            AttributeCollection attributes = TypeDescriptor.GetAttributes(type);
            foreach (Attribute a in attributes)
                if (a is WorkNodeTypeAttribute)
                    return ((WorkNodeTypeAttribute)a);
            return new WorkNodeTypeAttribute(type.Name);
        }
    }
}
